package com.uziot.security.uaa.service;

import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;

/**
 * @author shidt
 * @version V1.0
 * @className UserDetailServiceImpl
 * @date 2020-08-26 14:38:53
 * @description
 */
@Service
public class UserDetailServiceImpl implements UserDetailsService {

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        UserDetails zhangsan = User.withUsername("zhangsan")
                .password(new BCryptPasswordEncoder().encode("123"))
                .authorities("p1").build();
        UserDetails lisi = User.withUsername("lisi")
                .password(new BCryptPasswordEncoder().encode("123"))
                .authorities("p2").build();
        if ("zhangsan".equals(username)) {
            return zhangsan;
        }
        if ("lisi".equals(username)) {
            return lisi;
        }
        return null;
    }
}
